package com.yzz.hzraisedust.hzraseidust.util;

import android.content.Context;
import android.provider.CalendarContract;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Network;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.net.InterfaceAddress;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhengzhen on 2017/8/19.
 */

public class NetUtil {
    public interface  OpreationData{
        void opreationData(String json);
    }

    private static RequestQueue mRequestQueue;
    public NetUtil(Context context){
        if(mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(context);
        }
    }
    public void requestData(Response.Listener<String> resonse,Response.ErrorListener errorListener,String requestUrl, final Map<String,String> param){

        StringRequest stringRequest  = new StringRequest(Request.Method.POST,requestUrl , resonse, errorListener){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return param;
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(20000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        mRequestQueue.add(stringRequest);
    }

}
